package com.ruoyi.hr.service.impl.bginfo;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.mapper.ProcedureMapper;
import com.ruoyi.hr.mapper.bginfo.BgEducationMapper;
import com.ruoyi.hr.service.bginfo.BgEducationService;
import com.ruoyi.hr.util.BaseResult;
import com.ruoyi.hr.util.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class BgEducationServiceImpl implements BgEducationService {

    @Autowired
    BgEducationMapper bgEducationMapper;

    @Autowired
    ProcedureMapper procedureMapper;

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findDataList(Map map, Authority authority) {
        return bgEducationMapper.findDataList(map, authority);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int add(Map map) {
        return bgEducationMapper.add(map);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int remove(String ids) {
        String[] idSplit = ids.split(",");
        int num = 0;
        for (String id : idSplit) {
            num += bgEducationMapper.remove(id);
        }
        return num;
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public BaseResult procedure(String allId){
        String[] array = allId.split(",");
        String sql;
        for (String s : array) {
            sql = "ESP_EDURENEW " + s;
            procedureMapper.executeProcedure(sql);
        }
        return BaseResult.build(ResultEnum.SUCCESS);
    }
}
